package com.hzhc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzhc.entity.GateConfig;
import com.hzhc.mapper.GateConfigMapper;
import com.hzhc.service.GateConfigService;
import com.hzhc.vo.GateConfigVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 卡口设备配置 服务实现类
 * </p>
 *
 * @author 功不唐捐
 * @since 2024-06-19
 */
@Service
@RequiredArgsConstructor
public class GateConfigServiceImpl extends ServiceImpl<GateConfigMapper, GateConfig> implements GateConfigService {

    @Override
    public List<GateConfigVo> getList(Page<GateConfigVo> pagination, GateConfigVo vo) {
        IPage<GateConfigVo> iPage = baseMapper.selectGateConfigPage(pagination, vo);
        return iPage.getRecords();
    }

    @Override
    public boolean updateRet(GateConfigVo vo) {
        GateConfig config = new GateConfig();
        BeanUtils.copyProperties(vo, config);
        boolean b = updateById(config);
        return b;
    }

    @Override
    public boolean deleteRet(GateConfigVo vo) {
        GateConfig gateConfig = baseMapper.selectById(vo.getId());
        gateConfig.setDisable(true);
        boolean b = updateById(gateConfig);
        return b;
    }

    @Override
    public boolean addRet(GateConfigVo vo) {
        vo.setCreateTime(LocalDateTime.now());
        GateConfig config = new GateConfig();
        BeanUtils.copyProperties(vo, config);
        boolean b = save(config);
        return b;
    }
}
